import java.util.TreeMap;

public class Solution975 {
    public int oddEvenJumps(int[] arr) {
        boolean[][] f=new boolean[arr.length][2];
        TreeMap<Integer,Integer> treeMap=new TreeMap<>();
        f[arr.length-1][0]=f[arr.length-1][1]=true;
        treeMap.put(arr[arr.length-1],arr.length-1);
        for (int i=arr.length-2;i>=0;i--){
            Integer a=treeMap.ceilingKey(arr[i]);
            if (a!=null && f[treeMap.get(a)][1]){
                f[i][0]=true;
            }
            Integer b=treeMap.floorKey(arr[i]);
            if (b!=null && f[treeMap.get(b)][0]){
                f[i][1]=true;
            }
            treeMap.put(arr[i],i);
        }
        int ans=0;
        for (int i=0;i< arr.length;i++){
            if (f[i][0]){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution975().oddEvenJumps(new int[]{10,13,12,14,15}));
    }
}
